mini.parse();
var baseUrl = "http://localhost:8080/DSMP";
var grid=mini.get("grid1");
//分页控件
var pager = grid.getBottomPager();
var form= new mini.Form("#form1");
var qqq=[
    { "id": "0", "text": "小型车" },
    { "id": "1", "text": "中型车" },
    { "id": "2", "text": "大型车" },
]
var www=[
    { "id": "0", "text": "空闲" },
    { "id": "1", "text": "有计划" },
    { "id": "2", "text": "忙碌" },
]
var eee=[
    { "id": "0-20", "text": "0-20" },
    { "id": "20-50", "text": "20-50" },
    { "id": "50-100", "text": "50-100" },
    { "id": "100-150", "text": "100-150" },
]
var carType=mini.get("carType");
carType.setData(qqq);
var carState=mini.getByName("carState");
carState.setData(www);
var salary=mini.get("salary");
salary.setData(eee);
(function(){
    request('0',pager.getPageSize());
})();


//跳转增加页面
function addRow(){
    mini.open({

        targetWindow: window,
        url:"carInfo.html",
        title:"新增车辆信息",
        height:700,
        width:1300,
        showMaxButton: true,
        showModal:Boolean,
        allowResize:Boolean,
        setReadOnly:false,
        onload: function () {

        },
        ondestroy: function (action) {
            if(action=="ok"){
                request('0',pager.getPageSize())

            }
        }
    })
}
//跳转编辑页面
function editRow(){
    var row=grid.getSelected();

    if(row!=undefined){
        mini.open({

            targetWindow: window,
            url:"carInfo.html",
            title:"车辆信息编辑",
            height:"90%",
            width:"90%",
            showMaxButton: true,
            showModal:Boolean,
            allowResize:Boolean,
            setReadOnly:false,
            onload: function () {
                var iframe = this.getIFrameEl();//备份这个跨子页面窗口
                var data = {  action: "edit",row:row };//父传值给子页面
                iframe.contentWindow.SetData(data);//跨字串后页面渲染data
            },
            ondestroy: function (action) {
                if(action=="edit"){


                }
            }
        })
    }else{
        mini.alert("请选择一条数据")
    }
}
//删除
function removeRow(){
    var rows=grid.getSelecteds();
    console.log(rows);
    var ids="";
    rows.forEach(function(item){
        ids+=item.carInfoId+",";
    })
    var param = {params:ids}

    params=JSON.stringify(param);
    if (rows.length>0) {        //当一条都不选时提示让选一条
        // var carId = grid.getSelected().carInfoId;
        $.ajax({
            url:baseUrl+"/carInfo/delCar.do",
            contentType: "application/json",
            data:params,
            type:"post",
            success:function (data) {
                mini.alert(data.msg)
                request('0',pager.pageSize);
            }
        })
    }else{
        mini.alert("请至少选中一行记录")
    }
}


function request(pageIndex,pageSize){
    var pageIndex = pager.getPageIndex()
    var pageSize = pager.getPageSize();

    var pageObj = {
        current: pageIndex,
        size: pageSize,
    }

    var pageStr = JSON.stringify(pageObj);
    $.ajax({
        url: baseUrl+"/carInfo/getAllCars.do",
        type: "post",
        contentType: "application/json",
        data:pageStr,
        success: function(data) {//请求成功完成后要执行的方法
            console.log(data);
            grid.setData(data.data);
            pager.set({"totalCount": data.total})
        },
        error:function(data){
            mini.alert(cuole);
        }
    });
}
function find(){
    var aaa=form.getData();

    console.log(aaa);
    aaa=JSON.stringify(aaa);
    console.log(aaa);
    $.ajax({
        url: baseUrl+"/carInfo/queryWhereCoulmn.do",
        type: "post",
        contentType: "application/json",
        data:aaa,
        success: function(data) {//请求成功完成后要执行的方法
            console.log(data);
            grid.setData('');
            grid.setData(data.obj);
            mini.after(data.msg)
        },
        error:function(data){
            mini.alert(cuole);
        }
    });
}


//分页
grid.on("beforeload", function (e) {
    //阻止本来的翻页功能
    e.cancel = true;
    //当前页码
    var cunrrentPageIndex = grid.getPageIndex();
    //点击按钮之后的页码
    var pageIndex = e.data.pageIndex;
    //设置当前页数值
    pager.set({"pageIndex": pageIndex});
    //数据总数
    //var pageCount = pubPageCount;
    pager.set({"pageIndex": pageIndex});
    request(pageIndex + 1, pager.getPageSize());
});

//刷新
function onRefresh(e) {
    list(pager.getPageIndex(), pager.getPageSize());
}


//条件查询清空条件
function clean() {
    form.reset();
}